//
//  FeeDetailCell.m
//  wtshoppingcite
//
//  Created by TW on 15/6/12.
//  Copyright (c) 2015年 TW. All rights reserved.
//

#import "FeeDetailCell.h"

@implementation FeeDetailCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}

-(void)createSubViews{
    
    int o = kWidth/3;
    int x = 3;
    int y = 0;
    float width = kWidth/6;
    int z = 100;
    NSArray *array = @[@"材料费",@"人工费",@"其他费用"];
    
    for (int j = 0;j<2; j++) {
        
        
        for (int i = 0; i < x; i++) {
            
            _titleLabel = [self createLabelWithFrame:CGRectMake(o*i, y, width, 30) text:array[i] font:12.0f textAli:NSTextAlignmentCenter textColor:MAIN_GRAY_COLOR];
            _titleLabel.numberOfLines = 0;
            [self addSubview:_titleLabel];
            
            UIView *seperateLine = [[UIView alloc]initWithFrame:CGRectMake(_titleLabel.right, y, 1, _titleLabel.height)];
            seperateLine.backgroundColor = MAIN_GRAY_COLOR;
            [self addSubview:seperateLine];
            
            
            UILabel* subtitleLabel = [self createLabelWithFrame:CGRectMake(seperateLine.right,y , width, 30) text:@"" font:12.0f textAli:NSTextAlignmentCenter textColor:MAIN_GRAY_COLOR];
            subtitleLabel.tag = z++;
            NSLog(@"i ＋ j%d",subtitleLabel.tag);
            [self addSubview:subtitleLabel];
            
            
            UIView *seperateLine1 = [[UIView alloc]initWithFrame:CGRectMake(subtitleLabel.right , y, 1, subtitleLabel.height)];
            seperateLine1.backgroundColor = MAIN_GRAY_COLOR;
            [self addSubview:seperateLine1];
            
            NSLog(@"%f%f",_titleLabel.bounds.origin.x,subtitleLabel.bounds.origin.x);
            
        }
        
        UIView *seperateLine = [[UIView alloc]initWithFrame:CGRectMake(0, _titleLabel.bottom, kWidth, 1)];
        seperateLine.backgroundColor = MAIN_GRAY_COLOR;
        [self addSubview:seperateLine];
        y = 30;
        x = 2;
        width = kWidth/4;
        o = kWidth/2;
        array = @[@"总计金额",@"付款方式"];
    }
    
    _markLabel = [self createLabelWithFrame:CGRectMake(5, 100-40, kWidth, 40) text:@"备注" font:13.0f textAli:NSTextAlignmentLeft textColor:MAIN_GRAY_COLOR];
    [self addSubview:_markLabel];
    
    UIView *seperateLine = [[UIView alloc]initWithFrame:CGRectMake(0, 100-1, kWidth, 1)];
    seperateLine.backgroundColor = MAIN_GRAY_COLOR;
    [self addSubview:seperateLine];
    
}

-(void)setPayment:(NSDictionary *)payment{
    if (_payment != payment) {
        _payment = payment;
        
        NSString *materialCost = [NSString stringWithFormat:@"%@",[payment objectForKey:@"materialCost"]];
        NSString *otherCost = [NSString stringWithFormat:@"%@",[payment objectForKey:@"otherCost"]];
        NSString *remark = [NSString stringWithFormat:@"%@",[payment objectForKey:@"remark"]];
        NSString *workCost = [NSString stringWithFormat:@"%@",[payment objectForKey:@"workCost"]];
        
        _markLabel.text =[NSString stringWithFormat:@"备注:%@",remark] ;
        
        NSString *total = [NSString stringWithFormat:@"%.2f",[materialCost floatValue]+ [otherCost floatValue] +[workCost floatValue]];
        NSMutableArray *title = [[NSMutableArray alloc]initWithCapacity:1];
        
        [title addObject:materialCost];
        [title addObject:workCost];
        [title addObject:otherCost];
        
        NSLog(@"%@",title);
       
        int y = 3;
        int z = 100;
        for (int j = 0;j<2; j++) {
            
            for (int i = 0  ; i < y; i++) {
                
                UILabel *label = (UILabel *) [self viewWithTag:z++];
//                NSLog(@"ij ＋ jj%d",label.tag);
                label.text = [NSString stringWithFormat:@"%@",title[i]];
            }
            
            y = 2;
            
            [title removeAllObjects];
            [title addObject:total];
            [title addObject:@"现金"];
        }
       
    }
    
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(UILabel*)createLabelWithFrame:(CGRect)frame text:(NSString*)text font:(int)font textAli:(NSTextAlignment)alig textColor:(UIColor*)tc{
    if(text == nil)
        text = @"";
    UILabel* label = [[UILabel alloc] initWithFrame:frame];
    label.text = text;
    label.font = [UIFont systemFontOfSize:font];
    label.textAlignment = alig;
    label.textColor = tc;
    label.backgroundColor = [UIColor clearColor];
    return label;
}

@end
